package com.zjg.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zjg.bean.Place;
import com.zjg.dao.iface.PlaceDao;
import com.zjg.db.utills.JdbcTemplate;

public class PlaceDaoImp implements PlaceDao {

	@Override
	public List getPlace() {
		String sql = "select * from place";
		List<Place> list = JdbcTemplate.query(sql, (rs) -> {
			List<Place> list0 = new ArrayList();
			try {
				while (rs.next()) {
					if (rs.getString(3).length() == 2) {
						Place place = new Place(rs.getInt(1), rs.getString(2), rs.getString(3));
						list0.add(place);
					}
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return list0;
		}, null);
		return list;
	}

	@Override
	public List<Place> getCity(String code) {
		String sql = "select * from place";
		List<Place> list = JdbcTemplate.query(sql, (rs) -> {
			List<Place> list0 = new ArrayList();
			try {
				while (rs.next()) {
					
					if (rs.getString(3).length()==4&&(rs.getString(3).substring(0,2)).equals(code)) {
						Place place = new Place(rs.getInt(1), rs.getString(2), rs.getString(3));
						
						list0.add(place);
					}
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return list0;
		}, null);
		return list;
	}

}
